package com.dyh.quickdemozwei.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: yhdong
 * @Date: 2021/9/1 11:09
 */
@RequestMapping("/sink")
@RestController
public class SinkController {

    ReentrantLock lock = new ReentrantLock();
    Condition c1 = lock.newCondition();

    @RequestMapping("/w")
    public Object w(){
        lock.lock();
        try {
            c1.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
        return "ok";
    }

    @RequestMapping("/r")
    public Object r(){
        lock.lock();
        try {
            c1.signal();
        } finally {
            lock.unlock();
        }
        return "ok";
    }
}
